<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    /**
     * 获取字符串中出现次数最多的单词
     * @param {string} str - 输入的字符串
     * @returns {object} - 返回一个对象，包含出现最多次数的单词列表和出现的次数
     */
    function getWordMax(str){
        // 移除字符串两端的空格，并转换为小写
        let text = str.trim().toLowerCase()
        // 使用正则表达式匹配所有单词，返回匹配到的单词列表
        const list = text.match(/[a-z]+/g)
        // 创建一个Map对象，用于存储每个单词出现的次数
        let map = new Map()
        // 遍历单词列表，统计每个单词出现的次数
        list.forEach(item => {
            // 如果Map中不存在当前单词，则添加到Map中，并初始化计数为0
            if(!map.has(item)){
                map.set(item,0)
            }
            // 单词出现次数加一
            map.set(item,map.get(item) + 1)
        })
        // 初始化最大单词出现次数为0
        let maxWordNum = 0
        // 初始化最大单词列表为空数组
        let maxWordList = []
        // 遍历Map，找出出现次数最多的单词
        for([key,value] of map.entries()){
            // 如果当前单词出现次数大于最大单词出现次数，则更新最大单词出现次数和最大单词列表
            if (value > maxWordNum){
                maxWordNum = value
                maxWordList = [key]
            } else if(value === maxWordNum){
                // 如果当前单词出现次数等于最大单词出现次数，则将当前单词添加到最大单词列表中
                maxWordList.push(key)
            }
        }
        // 返回包含最大单词列表和最大单词出现次数的对象
        return {
            maxWordList,
            maxWordNum
        }
    }

    const str = `JavaScript is a programming language that conforms to the ECMAScript specification.
JavaScript is high-level, often just-in-time compiled, and multi-paradigm. It has curly-bracket syntax,
dynamic typing, prototype-based object-orientation, and first-class functions. JavaScript is one of
the core technologies of the World Wide Web. Over 97% of websites use it client-side for web page
behavior, often incorporating third-party libraries. All major web browsers have a dedicated
JavaScript engine to execute the code on the user's device.`
    getWordMax(str)
</script>
</html>
